package edu.gxnu.cetcdemo.controller;

import edu.gxnu.cetcdemo.pojo.Message;
import edu.gxnu.cetcdemo.service.MessageService;
import edu.gxnu.cetcdemo.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("留言浏览接口")
    @GetMapping("")
    public Result queryMessage(){
        return messageService.queryMessage();
    }

    @ApiOperation("回复浏览接口")
    @GetMapping("/{id}")
    public Result queryReply(@PathVariable long id){
        return messageService.queryReply(id);
    }

    @ApiOperation("留言发布接口")
    @PostMapping("")
    public Result addMessage(@RequestBody Message message){
        return messageService.addMessage(message);
    }

    @ApiOperation("回复发布接口")
    @PostMapping("/{id}")
    public Result addReply(@RequestBody Message message, @PathVariable long id){
        return messageService.addReply(message, id);
    }

    @ApiOperation("留言删除接口")
    @DeleteMapping("/{id}")
    public Result delMessage(@PathVariable long id){
        return messageService.delMessage(id);
    }
}

